<template>
  <div class="init_main">
    <p class="name_sty">{{ name }}</p>
    <div class="query">
      <!-- 质控类型：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="一级质控流程" value="一级质控流程"> </el-option>
        <el-option label="二级质控流程" value="二级质控流程"> </el-option>
        <el-option label="三级质控流程" value="三级质控流程"> </el-option>
      </el-select> -->
      姓名：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="test" value="test"> </el-option>
      </el-select>
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="primary"
        @click="open_dialog('修改')"
        >修改</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="del_row"
        >删除</el-button
      > -->
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
      >
        <el-table-column
          prop="Data.工号"
          label="工号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.登录名"
          label="登录名"
          align="center"
        ></el-table-column>
        <el-table-column prop="Data.姓名" label="姓名" align="center">
          <template slot-scope="scope">
            <span style="color: blue" @click="goto_da(scope.row)">{{
              scope.row.Data.姓名
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="Data.性别"
          label="性别"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.科室"
          label="科室"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.用户类型"
          label="用户类型"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.护理职称"
          label="护理职称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.能级"
          label="能级"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.状态"
          label="状态"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.是否参加临床护理工作"
          label="是否参加临床护理工作"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.离院_岗时间"
          label="离院_岗时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.离院_岗类型"
          label="离院_岗类型"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Data.离院_岗原因"
          label="离院_岗原因"
          align="center"
        ></el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.CurrentPage"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div>
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <table border="1" style="width: 100%">
        <tr>
          <td class="tac">工号:</td>
          <td><el-input size="mini" v-model="form.工号"></el-input></td>
          <td class="tac">登录名:</td>
          <td><el-input size="mini" v-model="form.登录名"></el-input></td>
        </tr>
        <tr>
          <td class="tac">姓名:</td>
          <td><el-input size="mini" v-model="form.姓名"></el-input></td>
          <td class="tac">性别:</td>
          <td><el-input size="mini" v-model="form.性别"></el-input></td>
        </tr>
        <tr>
          <td class="tac">科室:</td>
          <td><el-input size="mini" v-model="form.科室"></el-input></td>
          <td class="tac">用户类型:</td>
          <td><el-input size="mini" v-model="form.用户类型"></el-input></td>
        </tr>
        <tr>
          <td class="tac">护理职称:</td>
          <td><el-input size="mini" v-model="form.护理职称"></el-input></td>
          <td class="tac">能级:</td>
          <td><el-input size="mini" v-model="form.能级"></el-input></td>
        </tr>
        <tr>
          <td class="tac">状态:</td>
          <td><el-input size="mini" v-model="form.状态"></el-input></td>
          <td class="tac">是否参加临床护理工作:</td>
          <td>
            <el-input
              size="mini"
              v-model="form.是否参加临床护理工作"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td class="tac">离院_岗时间:</td>
          <td><el-input size="mini" v-model="form.离院_岗时间"></el-input></td>
          <td class="tac">离院_岗类型:</td>
          <td><el-input size="mini" v-model="form.离院_岗类型"></el-input></td>
        </tr>
        <tr>
          <td class="tac">离院_岗原因:</td>
          <td colspan="3">
            <el-input size="mini" v-model="form.离院_岗原因"></el-input>
          </td>
        </tr>
        <!-- <tr>
          <td class="tac">备注：</td>
          <td>
            <el-input type="textarea" :rows="6" v-model="form.备注"></el-input>
          </td>
        </tr> -->
        <!-- <tr>
          <td class="tac">人员：</td>
          <td colspan="3">
            <table border="1" cellspacing="0" style="width: 100%">
              <tr>
                <th class="tac">姓名</th>
                <th class="tac">操作</th>
              </tr>
              <tr v-for="(item, index) in form.users" :key="index">
                <td>
                  <el-select
                    v-model="item.UserId"
                    filterable
                    placeholder="请选择"
                    style="width: 100%"
                  >
                    <el-option
                      :label="item.Name"
                      :value="item.UserId"
                      v-for="(item, index) in userList"
                      :key="index"
                    >
                    </el-option>
                  </el-select>
                </td>
                <td>
                  <el-button @click="form.users.splice(index, 1)"
                    >删除</el-button
                  >
                </td>
              </tr>
              <tr>
                <td colspan="4">
                  <el-button
                    style="width: 100%"
                    size="small"
                    @click="form.users.push({})"
                    >添加一行</el-button
                  >
                </td>
              </tr>
            </table>
          </td>
        </tr> -->
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        CurrentPage: 1,
        pageSize: 10,
        total: 0,
        tableName: "人员管理",
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: null,
      form: { users: [] },
      userList: [],
      tableName: "人员管理",
    };
  },
  mounted() {
    this.name = this.$route.meta.title;
    this.getUserList();
    this.getList();
  },
  methods: {
    getList() {
      this.$post("/Bs/GetPageList", this.query).then((res) => {
        this.tableData = res.Data.PageList;
        this.query.total = res.Data.Total;
      });
    },
    getUserList() {
      this.$post("/Bs/GetAllUserList").then((res) => {
        this.userList = res.Data;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = null;
        return;
      }
      this.row_info = row;
    },
    del_row() {
      this.$post("/Bs/Delete/" + this.tableName + "/" + this.row_info._id).then(
        (res) => {
          this.getList();
        }
      );
    },
    handleClose() {
      this.form = {};
      this.dialogVisible = false;
    },
    btn_ok() {
      var url = this.form._id ? "/Bs/UpdateData" : "/Bs/InsertData";
      var body = {
        tableName: this.tableName,
        data: this.form,
      };
      this.$post(url, body).then((res) => {
        this.getList();
        this.handleClose();
      });
    },
    open_dialog(val) {
      this.dialog_title = val + "质控人员";
      if (val == "新增") {
        this.dialogVisible = true;
        return;
      }
      if (val == "修改" && this.row_info) {
        this.form = this.row_info.Data;
        this.dialogVisible = true;
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.query.CurrentPage = 1;
    },
    handleCurrentChange_page(val) {
      this.query.CurrentPage = val;
      this.getList();
    },
    goto_da(val) {
      console.log(val);
      this.$router.push(
        "/RYDA/daxx?人员ID=" +
          val._id +
          "&人员姓名=" +
          val.Data.姓名 +
          "&按钮权限=true"
      );
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
</style>